;;; yisp-visit-track.el --- tracks the visit point while work in buffers. 

;; Copyright (C) 2007  Free Software Foundation, Inc.

;; Author: Duzy Chan <duzy@duzy.info>
;; Keywords: lisp

;; This file is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; This file is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;; Boston, MA 02111-1307, USA.

;;; Commentary:

;; Keep visit-tracks between buffers.

;;; Code:

(defvar yisp-visit-tracks nil)

(defun yisp-visit-track-p(obj)
  "Predicates to test whether OBJ is an visit-track"
  (if (consp obj)
      (and (stringp (car obj))
           (integerp (cdr obj)))
    nil))

(defun yisp-visit-track-current-track()
  "Retrieves the current visit-track and returns it."
  (let ((cur-buf (buffer-name (current-buffer)))
        (pos (point)))
    (if (not (eq cur-buf nil)) (cons cur-buf pos) nil)))

(defun yisp-visit-track-jump-to-track(track)
  "Jump to the valid visit-track."
  (if (and (not (eq track nil))
           (yisp-visit-track-p track))
      (let ((buf (car track))
            (pos (cdr track)))
        (switch-to-buffer buf)
        (goto-char pos))))

;;;###autoload
(defun yisp-visit-track-push()
  "Save the current position as a yisp-visit-track."
  (interactive)
  (if (eq 'yisp-visit-tracks nil)
      (setq yisp-visit-tracks '()))
  (let ((new-track (yisp-visit-track-current-track)))
    (push new-track yisp-visit-tracks)))

;;;###autoload
(defun yisp-visit-track-pop()
  "Restore the point to the last saved position."
  (interactive)
  (if (not (eq yisp-visit-tracks nil))
      (let ((track (car yisp-visit-tracks)))
        (yisp-visit-track-jump-to-track track))))

(provide 'yisp-visit-track)
;;; yisp-visit-track.el ends here

